{extends file="./main.tpl"}
{block name=head}
<script type="text/javascript">
$(document).ready(function(){
	//calculateQuantity();
	//calculateWeight();
});
function checkBillNo(theBtn)
{
	var dataString = "outChallanNo=" + $('#outChallanNo').val();
	$.ajax({
		type: "GET",
		url: "checkOutBillNo.php",
		data: dataString,
		dataType: 'json',
		success:function(data)
		{
			if(data != '')
			{
				alert(data[0]);
				$('#outChallanNo').val(data[1]);
				$('#outChallanNo').focus();
				return false;
			}
			else
			{
				if($(theBtn).val() == ' SUBMIT '){
				  $('#submitBtn').val(1);
				}else{
				  $('#printBtn').val(1);
			  }
				$('#form1').submit();
			}
		}
  });
}
function calculateQuantity(enteredQuantity)
{
	var row = $(enteredQuantity).parents('.trRow');
	var entQuantity = parseFloat(row.find(".dispatchQuantity").val());
	var quantity    = parseFloat(row.find(".quantity").val());
	
	if(entQuantity <= quantity)
	{
	  var remainingQuantity = (quantity - entQuantity);
	  row.find("#remainingQuantity").val(remainingQuantity);
	}
	else
	{
		alert("Outgoing Quantity cannot be more. Please put less quantity......");
		row.find("#dispatchQuantity").val(quantity);
		row.find("#remainingQuantity").val(0);
		row.find("#dispatchQuantity").focus();
		return false;
	}
	
}
function calculateWeight(enteredWeight)
{
	var row = $(enteredWeight).parents('.trRow');
	var entWeight = parseFloat(row.find(".dispatchWeight").val());
	var weight    = parseFloat(row.find(".weight").val());
	
	if(entWeight <= weight)
	{
		var remainingWeight = (weight - entWeight);
	  row.find("#remainingWeight").val(remainingWeight);
	}
	else
	{
		alert("Outgoing Weight cannot be more. Please put less weight......");
		row.find("#dispatchQuantity").val(weight);
		row.find("#dispatchWeight").val(0);
		row.find("#dispatchWeight").focus();
		return false;
	}
}
</script>
{/block}
{block name=body}
<form name="form1" id="form1" action="{$smarty.server.PHP_SELF}" method="post" onSubmit="return confirm('Do You Want To Submit...!!!!');">
<input type="hidden" name="unprocessincomingId" value="{$unprocessincomingId}" />
<table border='0' cellpadding='1' cellspacing='2' align='center'>
<tr><td colspan="13" class="table1" align="center">* * Out Going Entry * *</td></tr>
<tr>
	<td colspan="6" class="table1" align="right">Party : </td>
	<td colspan="7" class="table1" align="left">
		{if $unprocessincomingId > 0}
      <select name="partyId" id="partyId" READONLY >
    {else}
      <select name="partyId" id="partyId" onchange="this.form.submit();" AUTOFOCUS>
    {/if}
        <option value="">All</option>
        {html_options values=$catTitleArray.partyId output=$catTitleArray.partyName selected=$selPartyId }
      </select>
	</td>
</tr>
{if $selPartyId > 0}
	<tr>
		<td  class="table1" align='center' colspan="3">Outgoing Challan No :</td>
		<td  class="table2" align='left' colspan="3"><input type="text" name="outChallanNo" id="outChallanNo" value="{$outGoingChallan}" /></td>
		<td  class="table1" align='center' colspan="2">Date :</td>
		<td  class="table1" align='left'   colspan="5">{html_select_date prefix="date" start_year ="-0" end_year="+2" field_order="DMY" month_format="%m" day_value_format="%02d"} </td>
	</tr>
  <tr>
  	<td  class="table1" align='center' rowspan="2"><b>Select</b></td>
  	<td  class="table1" align='center' rowspan="2"><b>Challan</b></td>
  	<td  class="table1" align='center' rowspan="2"><b>Party</b></td>
  	<td  class="table1" align='center' rowspan="2"><b>Process 1</b></td>
  	<td  class="table1" align='center' rowspan="2"><b>Process 2</b></td>
  	<td  class="table1" align='center' rowspan="2"><b>Process 3</b></td>
  	<td  class="table1" align='center' rowspan="2"><b>Final Process</b></td>
  	<td  class="table1" align='center' colspan="3"><b>Quantity</b></td>
  	<td  class="table1" align='center' colspan="3"><b>Weight</b></td>
  </tr>
  <tr>
  	<td  class="table1" align='center'>Processed</td>
  	<td  class="table1" align='center'>Dispatch</td>
  	<td  class="table1" align='center'>Remaining</td>
  	<td  class="table1" align='center'>Processed</td>
  	<td  class="table1" align='center'>Dispatch</td>
  	<td  class="table1" align='center'>Remaining</td>
  </tr>
  {section name="sec" loop=$plannArray}
  {if $plannArray[sec]['planningId']}
  <tr id="{$smarty.section.sec.rownum}" class="trRow">
    <td class="table2" align="center"><input type="checkbox" name="selectedIncomingId[{$smarty.section.sec.index}]" value="{$plannArray[sec].incomingId}" onclick="calculateQuantity(this);calculateWeight(this);" /></td>
    <td class="table2" align="left">{$plannArray[sec].challan}</td>
    <td class="table2" align="center" nowrap>{$plannArray[sec].partyName}</td>
    <td class="table2" align="center" nowrap>{$plannArray[sec].proName1}</td>
    <td class="table2" align="center" nowrap>{$plannArray[sec].proName2}</td>
    <td class="table2" align="center" nowrap>{$plannArray[sec].proName3}</td>
    <td class="table2" align="center" nowrap>
      <select name="finalProcessId[{$smarty.section.sec.index}]" id="finalProcessId">
        <option value="0">-- Select -- </option>
        {html_options values=$fpArray.finalProcessId output=$fpArray.finalProcessName}
      </select>  
    </td>
    <input type="hidden" name="planningId" value="{$plannArray[sec].planningId}" />
    <td class="table2" align="center">
    	{$plannArray[sec].quantity}
    	<input type="hidden" name="quantity[{$smarty.section.sec.index}]" value="{$plannArray[sec].quantity}" id="quantity" class="quantity" />
    </td>
    <td class="table2" align="center">
    	<input type="text" size="8" name="dispatchQuantity[{$smarty.section.sec.index}]" onblur="calculateQuantity(this);" value="{$plannArray[sec].quantity}" id="dispatchQuantity" class="dispatchQuantity" style="text-align:right;" />
    </td>
    <td class="table2" align="center">
    	<input type="text" size="8" name="remainingQuantity[{$smarty.section.sec.index}]" id="remainingQuantity" READONLY style="text-align:right;" value="" />
    </td>
    <td class="table2" align="center">
    	{$plannArray[sec].weight}
    	<input type="hidden" name="weight[{$smarty.section.sec.index}]" value="{$plannArray[sec].weight}" id="weight" class="weight" />
    </td>
    <td class="table2" align="center">
    	<input type="text" size="8" name="dispatchWeight[{$smarty.section.sec.index}]" onblur="calculateWeight(this);" value="{$plannArray[sec].weight}" id="dispatchWeight" class="dispatchWeight" style="text-align:right;" />
    </td>
    <td class="table2" align="center"><input type="text" size="8" name="remainingWeight[{$smarty.section.sec.index}]" id="remainingWeight" READONLY style="text-align:right;" /></td>
  </tr>
  {/if}
  {sectionelse}
  <tr>
    <td colspan="6" align="center">
      {$msg}
    </td>
  </tr>
  {/section}  
  {if $unprocessincomingId > 0}
  <tr>
  	<td colspan="9" class="table1" align="right">Unprocess Return Reason Note :</td>
  	<td colspan="9" class="table2" align="center"><textarea rows=3 cols=30 required="required" name="unprocessReturnNote"></textarea></td>
  </tr>
  {else}
    <input type="hidden" name="unprocessReturnNote" value=NULL />
  {/if}
  {if $selPartyId > 0}
    <tr>
    	<td colspan="13" class="table1" align="center">
    	  <input type="button" value=" SUBMIT " onclick="checkBillNo(this);" /><input type="hidden" name="submitBtn" id="submitBtn" value="0" />
    	  <input type="button" value=" PRINT " onclick="checkBillNo(this);" /><input type="hidden" name="printBtn" id="printBtn" value="0" />
    	</td>
    </tr>
  {/if}
{/if}
</table>
</form>
{/block}